/**
	Copyright (c) 2010 ATTi 
	All rights reserved.
	Author: Michael Shu
	Date: 2/25/2010
*/

@isTest
private class IOGQuickClosePageControllerTester {
	private static List<User> userList;
	private static User sysUser;
	private static ID IOGIncident_CASE_RecordType = RecordTypeHelper.GetRecordTypeID('Case', 'IOG Incident'); 
	
	private static void initialize(){
	    User u = new User();
		u.UserName = 'xyz_1234567890@atti-temp.com' + 'x';
		u.LastName = 'Michael Shu Test Email' + 'x';
		u.Email = 'xyz_1234567890@atti.com';
		u.Alias = 'abcde' + 'x';
		u.CommunityNickname = 'xyaz_1234556' + 'x';
		u.TimeZoneSidKey = 'America/Los_Angeles';
		u.LocaleSidKey = 'en_US';
		u.EmailEncodingKey = 'UTF-8';
		u.ProfileId = [select ID from Profile where Name = 'System Administrator' limit 1].Id;
		u.UserRoleId = [select ID from UserRole where Name = 'Information Systems' limit 1].Id;
		u.LanguageLocaleKey = 'en_US';
		Database.Saveresult sr = Database.insert(u);
		
		sysUser = [select ID from User where ID =: sr.getID() limit 1];

		List<Profile> profiles = [select ID, Name from Profile where Name like '%IOG Support%'];
		List<UserRole> nonsmeRoles = [select ID, Name from UserRole where Name like '%IOG%Support%'];
		List<UserRole> smeRoles = [select ID, Name from UserRole where Name like '%IOG%Product SME%'];
		List<User> users = new List<User>();
		for(Integer i = 0; i < 3 ; i++){
			User u_new = new User();
			u_new.UserName = 'IOG_test' + i + '@test.com' ;
			u_new.LastName = 'Michael Shu Test Email' + i;
			u_new.Email = 'xyz_1234567890@atti.com';
			u_new.Alias = 'abcde' + i;
			u_new.CommunityNickname = 'xyaz_1234556' + i;
			u_new.TimeZoneSidKey = 'America/Los_Angeles';
			u_new.LocaleSidKey = 'en_US';
			u_new.EmailEncodingKey = 'UTF-8';
			u_new.ProfileId = profiles[0].Id;
			u_new.LanguageLocaleKey = 'en_US';
			if(i < 2){
				u_new.UserRoleId = nonsmeRoles[i].Id;
			}else{
				u_new.UserRoleId = smeRoles[i-2].Id;
			}
			users.add(u_new);
		}
		Database.Saveresult[] lsr;
		System.runAs(sysUser){
			lsr = Database.insert(users);
		}
		Set<ID> uIDs = new Set<ID>();
		for(Database.Saveresult sr_new : lsr){
			uIDs.add(sr_new.getID());
		}
		userList = [select ID from User where ID IN: uIDs];
	}

    static testMethod void testQuickClose() {
    	initialize();
    	Case c = new Case();
		c.Subject = 'testQuickClose';
		c.Origin = 'Phone';
		c.Status = 'Open';
		c.CSS_CRF_RequestType__c = 'Not Defined';
		c.CSS_ProductFamily__c = 'ATT411';
		c.Priority = 'East';
		c.RecordTypeId = IOGIncident_CASE_RecordType;
		System.runAs(sysUser){
			insert c;
		}
		
		ApexPages.StandardController sc = new ApexPages.StandardController(c);
		IOGQuickClosePageController con = new IOGQuickClosePageController(sc);
		
		c.AFrontier_Issue__c = 'Issue A';
		c.AFrontier_Reason__c = 'Reason B';
		con.comments = 'test Comment C';
		System.runAs(sysUser){
			con.saved();
		}
		System.assertEquals('true', con.saveResult);
    }
}